package com.yyf.springboot2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyf.springboot2.entity.TGoods;
import com.yyf.springboot2.mapper.TGoodsMapper;
import com.yyf.springboot2.service.TGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yyf
 * @since 2019-05-29
 */
@Service
@Transactional

public class TGoodsServiceImpl extends ServiceImpl<TGoodsMapper, TGoods> implements TGoodsService {

    @Resource
    private  TGoodsMapper goodsMapper;

    @Override
    public List<TGoods> getGoodsList(Map<String, Object> map, Integer pageSize, Integer pageNum) {
//        QueryWrapper<TGoods> queryWrapper = new QueryWrapper<TGoods>();
//        queryWrapper.select("","");
//        Page<TGoods> page = new Page<>(pageNum,pageSize);  // 查询第1页，每页返回5条
//
//        IPage<TGoods> iPage = goodsMapper.selectPage(page,queryWrapper);
        List<TGoods> goodsList = null;


        if(pageSize != null && pageNum != null){
            map.put("pageSize",pageSize);
            map.put("pageNum",(pageNum -1) * pageSize);
        }else{
            map.put("pageSize",pageSize);
            map.put("pageNum",pageNum);
        }

        System.out.println((pageNum -1) * pageSize+"(pageNum -1) * pageSize");
        goodsList = goodsMapper.selectIndexGoods(map);



        return goodsList;
    }

    @Override
    public List <TGoods> getallGoods() {
        return goodsMapper.allGoods();
    }

    @Override
    public TGoods getgoodsDetails(Integer id) {
        QueryWrapper<TGoods> queryWrapper = new QueryWrapper<TGoods>();
        queryWrapper.select("id","categoryId","description","display","goodsName","goodsType","image","inventory",
       "itemName","hyPrice","dlPrice","pv","stat","type","price1","price2","price3","price4","price5","price6");
        queryWrapper.eq("id",id);
        return goodsMapper.selectOne(queryWrapper);
    }


}
